package com.dxg.msns.user.service.impl;

import com.dxg.msns.user.mapper.SingerGradeMapper;
import com.dxg.msns.user.pojo.SingerGrade;
import com.dxg.msns.user.service.SingerGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SingerGradeServiceImpl implements SingerGradeService {

    @Autowired
    private SingerGradeMapper singerGradeMapper;

    /**
     * 用户对歌手打分
     */
    public String rateSinger(String singerId, String userId, Integer grade) {
        if (grade < 1 || grade > 5) {
            return "评分必须在 1 到 5 之间。";
        }

        // 检查是否已经评分
        SingerGrade existing = singerGradeMapper.findBySingerIdAndUserId(singerId, userId);
        if (existing != null) {
            return "您已评分过该歌手，不能重复评分。";
        }

        // 构造评分对象
        SingerGrade singerGrade = new SingerGrade();
        singerGrade.setSingerId(singerId);
        singerGrade.setUserId(userId);
        singerGrade.setSingerGrade(grade);
        singerGrade.setCreateTime(new Date());
        singerGrade.setUpdateTime(new Date());
        singerGrade.setStatus(0);

        singerGradeMapper.insert(singerGrade);
        return "评分成功！感谢您的参与。";
    }
}
